package com.kc.web.controller.business;

import com.kc.business.domain.BizIndustry;
import com.kc.business.service.IBizIndustryService;
import com.kc.common.annotation.Log;
import com.kc.common.annotation.RepeatSubmit;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.enums.BusinessType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName BizIndustryController
 * @Description 行业Controller
 * @Author wangdongliang
 * @Date 2021/5/24 16:57
 */
@RestController
@RequestMapping("/business/industry")
public class BizIndustryController {
    @Resource
    private IBizIndustryService bizIndustryService;

    /**
     * 数据新增
     * @param bizIndustry
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:industry:add')")
    @Log(title = "行业数据管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @RepeatSubmit
    public AjaxResult add(@Validated @RequestBody BizIndustry bizIndustry) {
        bizIndustryService.add(bizIndustry);
        return AjaxResult.success();
    }
    /**
     * 数据编辑
     * @param bizIndustry
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:industry:update')")
    @Log(title = "行业数据管理", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    @RepeatSubmit
    public AjaxResult update(@Validated @RequestBody BizIndustry bizIndustry) {
        bizIndustryService.update(bizIndustry);
        return AjaxResult.success();
    }

    /**
     * 获取数据列表
     * @param bizIndustry
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:industry:list')")
    @GetMapping("/list")
    public AjaxResult list(BizIndustry bizIndustry) {
        List<BizIndustry> list = bizIndustryService.getList(bizIndustry);
        return AjaxResult.success(list);
    }

    /**
     * 删除师承数据
     */
    @PreAuthorize("@ss.hasPermi('business:industry:remove')")
    @Log(title = "行业数据管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{id}")
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Integer id) {
        BizIndustry bizIndustry = new BizIndustry();
        bizIndustry.setId(id);
        bizIndustry.setIsDeleted(1);
        return AjaxResult.success(bizIndustryService.update(bizIndustry));
    }
}
